<style>
    .site-demo-button {
        margin: 20px 0 10px 0
    }
</style>
<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main">

        <fieldset class="layui-elem-field site-demo-button" style="margin: 30px;">
            <legend>恢复出厂</legend>
            <div style="margin: 30px;">
                <button type="button" class="layui-btn layui-btn-warm" lay-event="restore">恢复出厂设置</button>

            </div>
        </fieldset>

        <fieldset class="layui-elem-field site-demo-button" style="margin: 30px;">
            <legend>系统重启</legend>
            <div style="margin: 30px;">
                <button type="button" class="layui-btn layui-btn-normal" lay-event="rebooting">重启操作系统</button>

            </div>
        </fieldset>

        <fieldset class="layui-elem-field site-demo-button" style="margin: 30px;">
            <legend>断电重启</legend>
            <div style="margin: 30px;">
                <button type="button" class="layui-btn layui-btn-danger" lay-event="outage">断电重启网关</button>

            </div>
        </fieldset>

    </div>
</div>

<script>
    layui.use(['form', 'table', 'miniPage', 'element'], function() {
        var $ = layui.jquery,
            layer = layui.layer;

        $("button[lay-event='rebooting']").click(function() {
            layer.confirm('确认重新启动操作系统？', {
                title: "提示",
                btnAlign: 'c',
                closeBtn: 0,
                btn: ['确认', '取消']
            }, function() {
                $.ajax({
                    url: '/xapi/reboot',
                    type: "POST",
                    data: {
                        "status": "rebooting",
                        "time": +new Date()
                    },
                    success: function(data) {
                        if (data.code === 0) {
                            layer.msg(data.desc, {
                                icon: 1
                            });
                        }
                    },
                });
            });
        })
        $("button[lay-event='restore']").click(function() {
            layer.confirm('恢复出厂设置后所有配置将被清除，确认恢复？', {
                title: "提示",
                btnAlign: 'c',
                closeBtn: 0,
                btn: ['确认', '取消']
            }, function() {
                $.ajax({
                    url: '/xapi/restore',
                    type: "POST",
                    data: {
                        "status": "restore",
                        "time": +new Date()
                    },
                    success: function(data) {
                        if (data.code === 0) {
                            layer.msg(data.desc, {
                                icon: 1
                            });
                        }
                    },
                });
            });
        })

        $("button[lay-event='outage']").click(function() {
            layer.confirm('系统将断电10秒后重新启动，确认冷重启网关？', {
                title: "提示",
                btnAlign: 'c',
                closeBtn: 0,
                btn: ['确认', '取消']
            }, function() {
                $.ajax({
                    url: '/xapi/hardreboot',
                    type: "POST",
                    data: {
                        "status": "outage",
                        "time": +new Date()
                    },
                    success: function(data) {
                        if (data.code === 0) {
                            layer.msg(data.desc, {
                                icon: 1
                            });
                        }
                    },
                });
            });
        })
    })
</script>